define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'room/users/index' + location.search,
                    add_url: 'room/users/add',
                    edit_url: '',
                    del_url: 'room/users/del',
                    multi_url: '',
                    import_url: '',
                    table: 'room_users',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                // search: false,
                // commonSearch: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'room_id', title: __('Room_id')},
                        // {field: 'user_id', title: __('User_id')},
                        // {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('系统手机号'), operate: 'LIKE'},
                        {
                            field: 'bindgame.game_avatar', title: "游戏头像",
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.image
                        },
                        {field: 'bindgame.game_nickname', title: "游戏昵称", operate: 'LIKE'},
                        {field: 'bindgame.game_number', title: "游戏ID", operate: 'LIKE'},
                        {field: 'award', title: __('Award'), operate: 'BETWEEN'},
                        {field: 'result', title: '排名'},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {"0": "已离开", "1": "房间内", "2": "已结算"},
                            formatter: Table.api.formatter.flag
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'updatetime',
                            title: __('Updatetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
